using System.Collections.Generic;
using UIExpand;
using UnityEngine;

public class DummyTecChat : MonoBehaviour
{
    public TecChatObj lastMatchChat { get { return m_MatchTecChats.Count > 0 ? m_MatchTecChats[m_MatchTecChats.Count - 1] : null; } }
    [SerializeField]
    TecChatObj.ChatType m_MatchChatType;
    [SerializeField]
    bool m_HideChat = false;
    SpriteChanger m_SpriteChanger;
    List<TecChatObj> m_MatchTecChats = new List<TecChatObj>();
    private void Awake()
    {
        m_SpriteChanger = GetComponent<SpriteChanger>();
        if (!m_HideChat)
            m_SpriteChanger.ChangeToIndex((int)m_MatchChatType);
    }
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }
    public bool IsMatch()
    {
        return m_MatchTecChats.Count > 0;
    }
    public void DestroyChat()
    {
        for (var i = 0; i < m_MatchTecChats.Count; ++i)
        {
            IntersectionObjManager.Instance.CycleObj(m_MatchTecChats[i].gameObject);
        }
        m_MatchTecChats.Clear();
    }
    public void OnTriggerEnter2D(Collider2D collision)
    {
        var techChatObj = collision.GetComponent<TecChatObj>();
        if (techChatObj && (techChatObj.chatType == m_MatchChatType || (m_MatchChatType == TecChatObj.ChatType.ChatCommmon && (int)techChatObj.chatType < 9)))
        {
            techChatObj.timePause = true;
            m_MatchTecChats.Add(techChatObj);
        }
    }
    public void OnTriggerExit2D(Collider2D collision)
    {
        var techChatObj = collision.GetComponent<TecChatObj>();
        if (techChatObj && (techChatObj.chatType == m_MatchChatType || (m_MatchChatType == TecChatObj.ChatType.ChatCommmon && (int)techChatObj.chatType < 9)))
        {
            techChatObj.timePause = false;
            m_MatchTecChats.Remove(techChatObj);
        }
    }
}
